package arithmetic.LeetCode.Move_Zeroes;

/**
 * @author zhangyanqi
 * @since 1.0 2017/10/12
 */
public class Solution {

    public void moveZeroes(int[] nums) {
        int indexA = 0;
        for (int i = 0; i < nums.length; i++) {
            int num1 = nums[indexA];
            int num2 = nums[i];
            if (num1 != 0) {
                indexA++;
                continue;
            }
            if (num1 == 0) {
                if (num2 != 0) {
                    nums[indexA] = num2;
                    nums[i] = 0;
                    indexA++;
                }
                if (indexA == nums.length) {
                    return;
                }
            }
        }
    }


    public static void main(String[] args) {
        int[] i = {1, 0, 0}; //[1,3,12,0,0]  [0,1,0,3,12][1,0,0]
        new Solution().moveZeroes(i);
        for (int m = 0; m < i.length; m++) {
            System.out.println(i[m]);
        }
    }
}
